/**
 * @file   main.cpp
 * @author ywl <ywl@ywl-VirtualBox>
 * @date   Fri Nov 25 22:49:35 2022
 * 
 * @brief  A test for the efficiency of heapsort and quicksort algorithms.
 * 
 * 
 */

#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include "Sorting.h"
using namespace std;

/** 
 * Print the elements of vector by desired style.
 * 
 * @param vec 
 */
template <typename T>
void print(vector<T>& vec)
{
  cout << "{ ";
  for (const T & n : vec)
      cout << n << ", ";
  cout << "\b\b" << " }" << endl << endl;  
}


/// Test program
int main(int argc, char *argv[])
{
    // Create file-reader and clock.
    ifstream file;
    time_t start;
    time_t end;
    
    // Open the file containing randomly ordered data.
    file.open("number.txt");
    int temp;
    
    vector<int> vec1(0);
    while(!file.eof()){
        file >> temp;
        vec1.push_back(temp);
    }
    vector<int> vec2{vec1};

    cout << "Size: " << vec1.size() << endl;
    /// cout << "Primary Sequence: " << endl;
    /// print(vec);

    /**
     * Heapsort
     */
    cout << "Heapsort:" << endl;
    start = clock();
    heapsort(vec1);
    end = clock();
    
    // Calculate running time(measured in second)
    double runtime = (double) (end - start) / CLOCKS_PER_SEC;
    cout << "Time consuming: " << runtime <<  "s" << endl;


    /**
     * Quicksort
     */
    cout << "Quicksort:" << endl;
    start = clock();
    quicksort(vec2);
    end = clock();
    
    // Calculate running time(measured in second)
    runtime = (double) (end - start) / CLOCKS_PER_SEC;
    cout << "Time consuming: " << runtime <<  "s" << endl;
    
    return 0;
}
